<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>留言界面</title>
    <style>
        body {
            background-image: url('../images/3.jpg');
            background-size: cover;
            font-family: Arial, sans-serif;
        }
        .main-content {
            padding: 20px;
        }
        h1{
            text-align: center;
        }
        span{
            font-size: 20px;
        }
        a{
            color: black;
            text-decoration: none;
        }
        .header-links {
            position: fixed;
            top: 10px; 
            right: 20px; 

        }
        .header-link {
            color: #b21818;
            text-decoration: none;
            margin-left: 10px;
            margin-right: 5px;
        }
        .header-link:hover {
            text-decoration: underline;
            margin-left:0 ;
            background-color: #ffffff;
        }
        /* 表单容器样式 */
        .form-container {
            display: flex;
            justify-content: center;
            align-items: center;
            width: 100%;
            min-height: 80vh; 
        }

        /* 表单样式 */
        form {
            display: flex;
            flex-direction: column;
            align-items: center;
            background: #fff;
            padding: 20px;
            border-radius: 8px;
            box-shadow: 0 4px 10px rgba(0, 0, 0, 0.1);
            width: 100%;
            max-width: 400px; 
        }

        /* 表单组样式 */
        .form-group {
            width: 100%;
            margin-bottom: 15px; 
        }

        /* 标签和输入框样式 */
        .form-group label {
            display: block;
            margin-bottom: 5px;
            color: #666;
        }

        .form-group input[type="text"],
        .form-group textarea {
            width: 100%;
            padding: 10px;
            border: 1px solid #ddd;
            border-radius: 4px;
            box-sizing: border-box; 
        }

        /* 输入框悬停效果 */
        .form-group input[type="text"]:hover,
        .form-group textarea:hover {
            border-color: #b61717; 
        }

        /* 提交按钮样式 */
        button {
            padding: 10px 20px;
            margin-top: 10px;
            border: none;
            border-radius: 4px;
            background-color: #f12d2d;
            color: white;
            cursor: pointer;
            transition: background-color 0.3s ease;
        }
        /* 提交按钮悬停效果 */
        button:hover {
            background-color: #a11313;
        }
        h2{
            text-align: center;
        }
    </style>
    <script>
        document.addEventListener('DOMContentLoaded', function() {
            const form = document.querySelector('form');
            const titleInput = document.getElementById('title');
            const authorInput = document.getElementById('author');
            const contentInput = document.getElementById('content');
            const statusInput = document.getElementById('status');
            function checkInputs() {
                if (!titleInput.value.trim() || !authorInput.value.trim() || !contentInput.value.trim()) {
                    alert('请填写所有必填字段。');
                    return false;
                }
                return true;
            }
            // 表单提交事件
            form.addEventListener('submit', function(event) {
                if (!checkInputs()) {
                    event.preventDefault(); // 阻止表单提交
                } else {
                    statusInput.value = '提交成功！';
                    // 这里可以添加代码发送数据到服务器
                    alert('留言已提交！');
                    // 重置表单
                    form.reset();
                }
            });
            // 动态添加必填字段样式
            function toggleRequiredFieldClass(element) {
                if (element.value.trim()) {
                    element.classList.add('required-field');
                } else {
                    element.classList.remove('required-field');
                }
            }
            titleInput.addEventListener('focus', function() {
                titleInput.classList.add('required-field');
            });
            authorInput.addEventListener('focus', function() {
                authorInput.classList.add('required-field');
            });
            contentInput.addEventListener('focus', function() {
                contentInput.classList.add('required-field');
            });

            titleInput.addEventListener('blur', function() {
                if (!titleInput.value.trim()) titleInput.classList.remove('required-field');
            });
            authorInput.addEventListener('blur', function() {
                if (!authorInput.value.trim()) authorInput.classList.remove('required-field');
            });
            contentInput.addEventListener('blur', function() {
                if (!contentInput.value.trim()) contentInput.classList.remove('required-field');
            });
        });
    </script>
</head>
<body>
<div class="main-content">
    <h1>请留下您的宝贵见解</h1>
    <div class="form-container">

    <form method="post" >
        <div class="form-group">
            <label for="title">title:</label>
            <input type="text" id="title" name="title" >
        </div>
        <div class="form-group">
            <label for="author">author:</label>
            <input type="text" id="author" name="author" >
        </div>
        <div class="form-group">
            <label for="content">context:</label>
            <textarea id="content" name="content" required></textarea>
        </div>
        <div class="form-group">
            <label for="status"></label>
            <input style="display: none;" type="text" id="status" name="status" readonly>
        </div>
        <div class="form-group">
            <label for="moreInfo">更多信息:</label>
            <input type="checkbox" id="moreInfo" name="moreInfo" onclick="showSubmenu('moreInfo')">
        </div>
        <div id="moreInfo-submenu" style="display: none;">
            <div class="form-group">
                <label for="additionalInfo">联系电话:</label>
                <input type="text" id="additionalInfo" name="additionalInfo">
                <label for="additionalInfo">邮箱:</label>
                <input type="text" id="additionalInfo" name="additionalInfo">
            </div>
        </div>
        <button type="submit">提交</button>
        <button type="reset">重置</button>
    </form>
    </div>
</div>

<script>
    function showSubmenu(type) {
        var submenu = document.getElementById(type + '-submenu');
        submenu.style.display = submenu.style.display === 'block' ? 'none' : 'block';
    }
</script>
<div class="header-links">
    <a href="../index.html" class="header-link">回到主页</a>
</div>
</body>
</html>